import { ipcInvoker } from "./electron.ts";
import type { RendererShell } from "@common/ipc-types.ts";

export const shellInvoker: RendererShell = {
  beep() {
    return ipcInvoker.invokeNode("electron.shell.beep");
  },
  openPath(path: string): Promise<string> {
    return ipcInvoker.invokeNode("electron.shell.openPath", path);
  },
  openExternal(url: string, options?: Electron.OpenExternalOptions): Promise<void> {
    return ipcInvoker.invokeNode("electron.shell.openExternal", url, options);
  },
  showItemInFolder(fullPath: string) {
    return ipcInvoker.invokeNode("electron.shell.showItemInFolder", fullPath);
  },
  trashItem(path: string): Promise<void> {
    return ipcInvoker.invokeNode("electron.shell.trashItem", path);
  },
  readShortcutLink(shortcutPath: string): Promise<Electron.ShortcutDetails> {
    return ipcInvoker.invokeNode("electron.shell.readShortcutLink", shortcutPath);
  },
  writeShortcutLink(shortcutPath: string, operation: "create" | "update" | "replace", options: Electron.ShortcutDetails): Promise<boolean> {
    return ipcInvoker.invokeNode("electron.shell.writeShortcutLink", shortcutPath, operation, options);
  },
  openFileViaEditor(filePath: string, preferVsc?: boolean) {
    ipcInvoker.send("shell.openFileViaEditor", filePath, preferVsc);
  },
};
